using OpenBlock.Properties;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace OpenBlock.Item
{
    public class ItemState : System.IEquatable<ItemState>
    {
        public static readonly ItemState AIR = new ItemState(ItemId.Air);
        public ItemId id
        {
            get => (ItemId)root.GetUshort();
        }
        private Property root;

        public ItemState(ItemId id)
        {
            root = new Property((ushort)id);
        }

        public ItemState AddProperty(string tag, Property prop)
        {
            root.AddChild(tag, prop);
            return this;
        }

        public ItemState SetProperty(string tag, uint val)
        {
            if (root.GetChild(tag) is Property p)
            {
                p.Set(val);
            }
            else
            {
                AddProperty(tag, new Property(val));
            }
            return this;
        }

        public Property GetProperty(string tag)
        {
            return root.GetChild(tag);
        }

        public bool Equals(ItemState other)
        {
            return this.root == other.root;
        }
    }
}
